package com.my.fss.common.controller;

import com.my.fss.common.util.RequestUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseController {

    /**id生成器*/
//    @Autowired
//    public IdWorker idWorker;
    @Autowired
    public Environment env;

    /** 容器 */
    public HttpServletRequest request;
    public HttpServletResponse response;

    /** 权限部分参数 */
    public String companyId;
    public String companyName;
    public Object userInfo;


    /** 工具对象 */
    protected Log logger = LogFactory.getLog(getClass());
    public RequestUtil requestUtils;

    //使用shiro获取
    @ModelAttribute
    public void setResAnReq(HttpServletRequest request,HttpServletResponse response) {
        System.out.println("ModelAttribute");
        this.request = request;
        this.response = response;

        requestUtils = new RequestUtil(request);

        //获取session中的安全数据
//        Subject subject = SecurityUtils.getSubject();
//        //1.subject获取所有的安全数据集合
//        PrincipalCollection principals = subject.getPrincipals();
//        if(principals != null && !principals.isEmpty()){
//            //2.获取安全数据
//            ProfileResult result = (ProfileResult)principals.getPrimaryPrincipal();
//            this.userInfo = result;
//            this.companyId = result.getCompanyId();
//            this.companyName = result.getCompany();
//        }
    }

}
